<div class="page-header">
    <h1>
        公会信息列表
        <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
        </small>
    </h1>
</div>
<div class="row">
    <div class="col-xs-12">
        <table id="dtpList" class="dataTable">
            <tfoot>
            <tr>
                <td colspan="3">本页合计：</td>
                <td>
                    <span name="Family_Beans" class="tooltip-"/>
                </td>
                <td colspan="8"></td>
            </tr>
            </tfoot>
        </table>
        <div id="dtpList_filter" class="dataTables_filter">
            <div>
                <select id="dtpList_F_SType" class="selectpicker" data-style="btn btn-info btn-sm" data-width="90px">
                    <option value="">模糊查询</option>
                    <option data-divider="true"></option>
                    <option value="Family_ID">公会ID</option>
                    <option value="Family_Name">公会名称</option>
                    <option value="User_ID">公会长ID</option>
                    <option value="ContactName">公会联系人</option>
                    <option value="Family_Email">公会邮箱</option>
                    <option value="Family_Phone">公会电话</option>
                    <option value="Family_QQ">公会QQ</option>
                </select>
                <input id="dtpList_F_SValue" class="fvalue" type="text"/>
                <select id="dtpList_F_DateType">
                    <option value="Create_Date">注册时间</option>
                    <option value="Approve_Date">审核时间</option>
                </select>
                <input id="dtpList_F_StartDate" type="text" style="width: 76px;" placeholder="开始时间">
                <label>-</label>
                <input id="dtpList_F_EndDate" type="text" style="width: 76px;" placeholder="结束时间">
                <select id="dtpList_F_SelectDate"></select>
                <label>状态：</label>
                <select id="dtpList_F_Status">
                    <option value="-1">所有</option>
                    <option value="0" selected="selected">正常</option>
                    <option value="1">锁定</option>
                    <option value="2">申请</option>
                    <option value="3">拒绝</option>
                </select>
                <button id="dtpList_F_Advanced"></button>
                <button id="dtpList_F_Btn"></button>
            </div>
            <div>
                <label>艺人数量</label>
                <input id="dtpList_F_StartAnchorNum" type="text" style="width: 76px;" placeholder="开始数量">
                <label>-</label>
                <input id="dtpList_F_EndAnchorNum" type="text" style="width: 76px;" placeholder="结束数量">
                <label>结算方式：</label>
                <select id="dtpList_F_Settlement">
                    <option value="-1">所有</option>
                    <option value="1">默认</option>
                    <option value="2">对公</option>
                </select>
            </div>
        </div>
    </div>
</div>
<script src="<%- Virtual_Path.Static %>jquery.plugin/dataTables/jquery.dataTables.min.js"></script>
<script src="<%- Virtual_Path.Static %>jquery.plugin/dataTables/jquery.dataTables.bootstrap.min.js"></script>
<script>
    $(function () {
        //region 时间输入框插件
        $('#dtpList_F_StartDate, #dtpList_F_EndDate').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            minView: 2,
            autoclose: true
        });
        //endregion
        //region 绑定日期选择框
        $.KOC.Date.Select.Bind({
            eSelect: $('#dtpList_F_SelectDate'),
            eBegin: $('#dtpList_F_StartDate'),
            eEnd: $('#dtpList_F_EndDate')
        });
        //endregion
        //region dtpList
        var _dtpList = $("#dtpList").dataTable({
            'aoColumns': [
                {
                    'sWidth': '75px', 'data': 'Family_ID', 'sName': 'Family_ID', 'sTitle': '公会ID', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).html($('<a/>').attr('data-openwindow', ':FamilyInfo:' + cellData).text(cellData));
                    }
                },
                {
                    'data': 'Family_Name', 'sTitle': '公会名称', 'bSortable': false
                },
                {
                    'sWidth': '85px', 'data': 'ContactName', 'sTitle': '联系人', 'sClass': 'center t-left', 'bSortable': false
                },
                {
                    'sWidth': '8%', 'data': 'Family_Beans', 'sName': 'Family_Beans', 'sTitle': '公会金豆', 'sClass': 'center t-right',
                    'createdCell': function (td, cellData) {
                        if (cellData > 0) {
                            $(td).html('<span class="tooltip-" data-rel="tooltip" data-original-title="公会金豆价值：' + $.KOC.String.ToCurrencyPositiveStr(cellData / 1000) + '">' + cellData + '</span>');
                        }
                    }
                },
                {
                    'sWidth': '8%', 'data': 'Family_Beans', 'sName': 'Family_Beans_Total', 'sTitle': '获得总金豆', 'sClass': 'center t-right',
                    'createdCell': function (td, cellData) {
                        if (cellData > 0) {
                            $(td).html('<span class="tooltip-" data-rel="tooltip" data-original-title="获得总金豆价值：' + $.KOC.String.ToCurrencyPositiveStr(cellData / 1000) + '">' + cellData + '</span>');
                        }
                    }
                },
                {
                    'sWidth': '80px', 'data': 'Anchor_Num', 'sName': 'Anchor_Num', 'sTitle': '艺人数量', 'sClass': 'center t-right',
                    'createdCell': function (td, cellData, rowData) {
                        if (cellData > 0) {
                            $(td).html($('<a/>').attr('data-openwindow', ':FamilyInfo:' + rowData.Family_ID).text(cellData));
                        }
                    }
                },
                {
                    'sWidth': '80px', 'data': 'Settlement', 'sName': 'Settlement', 'sTitle': '结算方式', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        switch (cellData) {
                            case 1:
                                $(td).html('<span class="label label-success">默认</span>');
                                break;
                            case 2:
                                $(td).html('<span class="label label-danger">对公</span>');
                                break;
                            default:
                                $(td).html('<span class="label label-default">未知</span>');
                                break;
                        }
                    }
                },
                {
                    'sWidth': '10%', 'data': 'NickName', 'sTitle': '公会长', 'sClass': 'center t-left', 'bSortable': false,
                    'createdCell': function (td, cellData, rowData) {
                        $(td).html($('<a class="tooltip-" data-rel="tooltip" data-original-title="用户ID：'+ rowData.User_ID + '"/>').attr('data-openwindow', ':UserInfo:' + rowData.User_ID).html(cellData));
                    }
                },
                {
                    'sWidth': '9%', 'data': 'Family_Phone', 'sName': 'Family_Phone', 'sTitle': '公会电话', 'sClass': 'center'
                },
                {
                    'sWidth': '9%', 'data': 'Family_QQ', 'sName': 'Family_QQ', 'sTitle': '公会QQ', 'sClass': 'center t-left'
                },
                {
                    'sWidth': '9%', 'data': 'Create_Date', 'sName': 'Family_ID', 'sTitle': '创建日期', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).text(moment(cellData).format('YY/MM/DD HH:mm'));
                    }
                },
                {
                    'sWidth': '65px', 'data': 'Status', 'sName': 'Status', 'sTitle': '状态', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        switch (cellData) {
                            case 0:
                                $(td).html('<span class="label label-success">正常</span>');
                                break;
                            case 1:
                                $(td).html('<span class="label label-danger">锁定</span>');
                                break;
                            case 2:
                                $(td).html('<span class="label label-warning">申请</span>');
                                break;
                            case 3:
                                $(td).html('<span class="label label-grey">拒绝</span>');
                                break;
                            default:
                                $(td).html('<span class="label label-default">未知</span>');
                                break;
                        }
                    }
                }
            ],
            'aaSorting': [0, 'desc'],
            'sAjaxSource': '/ajax/user.page.familyinfo',
            'fnServerParams': function (aoData) {
                if (!this.arrPageFilter) {
                    this.arrPageFilter = {
                        F_DateType: $(this.selector + '_F_DateType').val(),
                        F_StartDate: $(this.selector + '_F_StartDate').val(),
                        F_EndDate: $(this.selector + '_F_EndDate').val(),
                        F_StartAnchorNum: $(this.selector + '_F_StartAnchorNum').val(),
                        F_EndAnchorNum: $(this.selector + '_F_EndAnchorNum').val(),
                        F_Settlement: $(this.selector + '_F_Settlement').val(),
                        F_Status: $(this.selector + '_F_Status').val()
                    };
                } else {
                    $(this.selector + '_F_DateType').val(this.arrPageFilter.F_DateType);
                    $(this.selector + '_F_StartDate').val(this.arrPageFilter.F_StartDate);
                    $(this.selector + '_F_EndDate').val(this.arrPageFilter.F_EndDate);
                    $(this.selector + '_F_StartAnchorNum').val(this.arrPageFilter.F_StartAnchorNum);
                    $(this.selector + '_F_EndAnchorNum').val(this.arrPageFilter.F_EndAnchorNum);
                    $(this.selector + '_F_Settlement').val(this.arrPageFilter.F_Settlement);
                    $(this.selector + '_F_Status').val(this.arrPageFilter.F_Status);
                }
                this.ofnServerParams(aoData);
            },
            'fnFooterCallback': function (nFoot, aData) {
                var Family_Beans = 0;
                _.forEach(aData, function (ThisValue) {
                    Family_Beans += ThisValue.Family_Beans;
                });
                $(nFoot).find('[name="Family_Beans"]').attr({
                    'data-rel': 'tooltip',
                    'data-original-title': '公会金豆价值总计：' + $.KOC.String.ToCurrencyPositiveStr(Family_Beans / 1000)
                }).text(Family_Beans);
            },
            'fnDrawCallback': function () {
                $.Common.Bootstrap.Tooltip(this);
                this.ofnDrawCallback();
            },
            'selectOpt': {
                Tools: {
                    Init: true,
                    Buttons: {
                        'btn-Family': {
                            text: '查看公会信息',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Family](Info)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':FamilyInfo:' + _dtpList.selectData.Family_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-Edit': {
                            text: '<i class="fa fa-pencil"></i> 修改公会信息',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Family](Edit)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':UserEdit:' + _dtpList.selectData.Family_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-close': {}
                    },
                    onBuild: function (content) {
                        $.CommonAdmin.Permission.CheckElement(content);
                    },
                    onReset: function () {
                        if (!_dtpList.selectData) {
                            return;
                        }
                        var _btn = ['btn-Family', 'btn-Edit'];
                        _dtpList.ofnSelectToolsBtnRemoveClass(_btn);
                    }
                }
            }
        });
        //endregion
    });
</script>